package com.home.fansea;

//import com.sun.org.omg.CORBA.InitializerSeqHelper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class shiroLoginText {
    @Test
    public void testShiro() {
        //1.初始化获取SecurityManager
        IniSecurityManagerFactory factory=new IniSecurityManagerFactory("classpath:shiro.ini");
        SecurityManager instance = factory.getInstance();

        SecurityUtils.setSecurityManager(instance);
        //2.获取Subject对象
        Subject subject = SecurityUtils.getSubject();
        //3.创建token对象，web应用从前端传递用户名和密码
        AuthenticationToken token=new UsernamePasswordToken("fansea","123456");
        //4.完成登录
        try {
            subject.login(token);
            System.out.println("登录成功" );
        }catch (UnknownAccountException e){
            e.printStackTrace();
            System.out.println("用户不存在");
        }catch (IncorrectCredentialsException e){
            e.printStackTrace();
            System.out.println("密码错误");
        }
    }
}

